import { defineStore } from 'pinia';

export const useConfigStore = defineStore('config', {
    state: () => ({
        stdout: '',
        runningFlag: false,
        maxLogCount: 10000 // 设置最大日志条数
      }),

    actions: {
        setStdoutLog(role, color, text) {
            if (role === 'user') {
                this.stdout += `<span style="color: #3de446">vitepress:~$ </span><span>${text}<span><br>`;
            }else{
                this.stdout += `<span style="color: ${color}">${text}</span><br>`;
            }

            // 控制日志数量
            const logs = this.stdout.split('<br>');
            if (logs.length > this.maxLogCount) {
                this.stdout = logs.slice(logs.length - this.maxLogCount).join('<br>');
            }
        },

        clearStdoutLog() {
            this.stdout = '';
        },
        setRunningFlag(flag) {
            this.runningFlag = flag;
        }
        

    }
    

})